package com.xmtlxx.web.controller.center;

import cn.hutool.core.bean.BeanUtil;
import com.xmtlxx.oms.domain.vo.*;
import com.xmtlxx.web.controller.oms.service.ITaskService;
import com.xmtlxx.web.controller.tms.service.IOrderService;
import com.xmtlxx.web.controller.tms.service.IWaybillService;
import com.xmtlxx.common.core.controller.BaseController;
import com.xmtlxx.common.core.domain.R;
import com.xmtlxx.common.core.domain.entity.SysDictData;
import com.xmtlxx.common.utils.DateUtils;
import com.xmtlxx.common.utils.StringUtils;
import com.xmtlxx.oms.domain.bo.TaskBo;
import com.xmtlxx.oms.service.ITaskDtlService;
import com.xmtlxx.system.service.ISysDictDataService;
import com.xmtlxx.tms.domain.vo.OrderVo;
import com.xmtlxx.tms.domain.vo.WaybillVo;
import com.xmtlxx.wms.domain.bo.InventoryBo;
import com.xmtlxx.wms.domain.vo.DataVo;
import com.xmtlxx.wms.service.IInventoryService;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

@Validated
@Api(value = "控制中心", tags = {"首页数据统计"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/statistics")
public class StatisticsController extends BaseController {

    private final ISysDictDataService iSysDictDataService;

    private final IInventoryService iInventoryService;

    private final ITaskService iTaskService;

    private final ITaskDtlService iTaskDtlService;

    private final IOrderService iOrderService;

    private final IWaybillService iWaybillService;

    @GetMapping("/indexCount")
    public R<Map<String,Object>> indexCount(){
        Map<String,Object> result = new HashMap<>();
        InventoryBo bo = new InventoryBo();
        bo.setType("0");
        result.put("properties",iInventoryService.countCurrentTotals(bo));
        /**
         * 统计取件物品条数跟取件物品数量
         */
        result.put("picks",iInventoryService.countPickupTotals(bo));
        bo.setType("1");
        result.put("bus",iInventoryService.countCurrentTotals(bo));
        return  R.ok(result);
    }

    @GetMapping("/indexCountv2")
    public R<Map<String,Object>> indexCountv2(){
        Map<String,Object> result = new HashMap<>();
        Long outnums = 0l;
        Long deals = 0l;
        Long tnums = 0l;
        Long rnums = 0l;
        Long eoutnums = 0l;
        Long etnums = 0l;
        InventoryBo bo = new InventoryBo();
        bo.setType("0");
        CurrentBiVo properties = iInventoryService.countCurrentTotals(bo);
        CurrentBiVo propertyNums = iInventoryService.countDatasTotals(bo);
        properties.setNums(propertyNums.getNums());
        result.put("properties",properties);

        if(propertyNums.getOutnums() != null){ outnums += propertyNums.getOutnums();}
        if(propertyNums.getDeals() != null){ deals += propertyNums.getDeals();}
        if(propertyNums.getTnums() != null){ tnums += propertyNums.getTnums();}
        if(propertyNums.getRnums() != null){ rnums += propertyNums.getRnums();}
        if(propertyNums.getEoutnums() != null){ eoutnums += propertyNums.getEoutnums();}
        if(propertyNums.getEtnums() != null){ etnums += propertyNums.getEtnums();}

        /**
         * 统计取件物品条数跟取件物品数量
         */
        result.put("picks",iInventoryService.countPickupTotals(bo));

        bo.setType("1");
        CurrentBiVo bus = iInventoryService.countCurrentTotals(bo);
        CurrentBiVo busNums = iInventoryService.countDatasTotals(bo);
        bus.setNums(busNums.getNums());
        result.put("bus",bus);

        if(busNums.getOutnums() != null){ outnums += busNums.getOutnums();}
        if(busNums.getDeals() != null){ deals += busNums.getDeals();}
        if(busNums.getTnums() != null){ tnums += busNums.getTnums();}
        if(busNums.getRnums() != null){ rnums += busNums.getRnums();}
        if(busNums.getEoutnums() != null){ eoutnums += busNums.getEoutnums();}
        if(busNums.getEtnums() != null){ etnums += busNums.getEtnums();}

        CurrentBiVo outs = new CurrentBiVo();
        outs.setOutnums(outnums);
        outs.setDeals(deals);
        outs.setTnums(tnums);
        outs.setRnums(rnums);
        outs.setEoutnums(eoutnums);
        outs.setEtnums(etnums);
        result.put("outs",outs);
        return  R.ok(result);
    }

    @GetMapping("/options/{action}")
    public R<Map<String,Object>> statisticsAction(@PathVariable String action){
        Map<String,Object> result = new HashMap<>();
        if(StringUtils.isNotEmpty(action)){
            switch (action){
                case "inventory":
                    result = statisticsInventory();
                    break;
                case "property":
                    result = statisticsProperty();
                    break;
                case "warehouse_left":
                    result = statisticsWarehouseLeft();
                    break;
                case "warehouse_right":
                    result = statisticsWarehouseRight();
                    break;
                case "exWarehouse":
                    result = statisticsExWarehouse();
                    break;
                case "order":
                    result = statisticsOrder();
                    break;
                case "waybill":
                    result = statisticsWaybill();
                    break;
                default:
                    break;
            }
        }
        return  R.ok(result);
    }

    /**
     * 库存情况
     * @return
     */
    public Map<String,Object> statisticsInventory(){
        Map<String,Object> data = new HashMap<>();
        //横轴
        List<String> xData = new ArrayList<>();
        //竖轴
        Map<String,List<Long>> yData = new HashMap<>();

        SysDictData dictData = new SysDictData();
        dictData.setDictType("wms_put_task_area");
        List<SysDictData> dictDataList = iSysDictDataService.selectDictDataList(dictData);

        List<DataVo> dataVos = iInventoryService.selectInventoryByList();

        List<DataVo> dictDataVos = dictDataList.stream().map(item->{
            DataVo vo = new DataVo();
            vo.setRegion(item.getDictValue());
            vo.setRegionName(item.getDictLabel());
            vo.setInnums(0l);
            vo.setOutnums(0l);
            vo.setDeals(0l);
            vo.setNums(0l);
            return vo;
        }).collect(Collectors.toList());

        //dataVos 合并到 dictDataVos
        List<DataVo> result = dictDataVos.stream().map(d->{
            dataVos.stream().filter(d2->Objects.equals(d.getRegion(),d2.getRegion())).forEach(d2->{
                BeanUtil.copyProperties(d2,d);
            });
            return d;
        }).collect(Collectors.toList());


        //横轴数据处理
        xData = result.stream().map(item->{
            String region = null;
            if(item.getRegion().equals("QB")){
                region = null;
            }
            else if(item.getRegion().equals("SZ")){
                region = "市直";
            }
            else if(item.getRegion().equals("YA")){
                region = item.getRegionName()+"市";
            }
            else if(item.getRegion().equals("SY") || item.getRegion().equals("SX")){
                region = item.getRegionName()+"区";
            }
            else {
                region = item.getRegionName()+"县";
            }
            return region;
        }).collect(Collectors.toList());

        //竖轴数组处理
        List<Long> innums = result.stream().map(item->{
            Long count = null;
            if(!item.getRegion().equals("QB")){
                count = item.getInnums();
            }
            return count;
        }).collect(Collectors.toList());

        List<Long> outnums = result.stream().map(item->{
            Long count = null;
            if(!item.getRegion().equals("QB")){
                count = item.getOutnums();
            }
            return count;
        }).collect(Collectors.toList());

        List<Long> deals = result.stream().map(item->{
            Long count = null;
            if(!item.getRegion().equals("QB")){
                count = item.getDeals();
            }
            return count;
        }).collect(Collectors.toList());

        List<Long> nums = result.stream().map(item->{
            Long count = null;
            if(!item.getRegion().equals("QB")){
                count = item.getNums();
            }
            return count;
        }).collect(Collectors.toList());
        //移除null
        xData.removeAll(Collections.singleton(null));
        innums.removeAll(Collections.singleton(null));
        outnums.removeAll(Collections.singleton(null));
        deals.removeAll(Collections.singleton(null));
        nums.removeAll(Collections.singleton(null));

        yData.put("innums",innums);
        yData.put("outnums",outnums);
        yData.put("deals",deals);
        yData.put("nums",nums);

        data.put("xData",xData);
        data.put("yData",yData);
        return  data;
    }

    /**
     * 财物统计
     * @return
     */
    public Map<String,Object> statisticsProperty(){
        Map<String,Object> data = new HashMap<>();
        //横轴
        List<String> xData = new ArrayList<>();
        //竖轴
        List<DataVo> yData = new ArrayList<>();

        List<DataVo> propertyList = iInventoryService.selectPropertyByList();

        if(propertyList != null && propertyList.size() > 0){
            xData = propertyList.stream().map(item->{
                return item.getName();
            }).collect(Collectors.toList());

            yData = propertyList.stream().map(item->{
                DataVo vo = new DataVo();
                vo.setValue(item.getNums());
                vo.setName(item.getName());
                return vo;
            }).collect(Collectors.toList());
        }
        data.put("xData",xData);
        data.put("yData",yData);
        return  data;
    }

    /**
     * 入库统计-左侧数据
     * @return
     */
    public Map<String,Object> statisticsWarehouseLeft(){
        Map<String,Object> data = new HashMap<>();
        //横轴
        List<String> xData = new ArrayList<>();
        //竖轴
        Map<String,List<Long>> yData = new HashMap<>();
        //过滤
        List<String> lData = new ArrayList<>();

        //查询入库数据
        List<TaskVo> taskVos = iTaskService.taskStatistics();

        SysDictData dictData = new SysDictData();
        dictData.setDictType("oms_property_type");
        List<SysDictData> dictDataList = iSysDictDataService.selectDictDataList(dictData);

        //taskVo转dataVo
        List<DataVo> taskData = taskVos.stream().map(item->{
            DataVo vo = new DataVo();
            vo.setName(item.getDeptName());
            vo.setRegion(item.getDictValue());
            vo.setRegionName(item.getDictLabel());
            vo.setGenerallys(item.getGenerallys());
            vo.setPreciouses(item.getPreciouses());
            vo.setLarges(item.getLarges());
            vo.setCars(item.getCars());
            return  vo;
        }).collect(Collectors.toList());

        List<DataVo> dictDataVos = dictDataList.stream().map(item->{
            DataVo vo = new DataVo();
            vo.setRegion(item.getDictValue());
            vo.setRegionName(item.getDictLabel());
            vo.setGenerallys(0l);
            vo.setPreciouses(0l);
            vo.setLarges(0l);
            vo.setCars(0l);
            return vo;
        }).collect(Collectors.toList());

        //taskData 合并到 dictDataVos
        List<DataVo> result = dictDataVos.stream().map(d->{
            taskData.stream().filter(d2->Objects.equals(d.getRegion(),d2.getRegion())).forEach(d2->{
                BeanUtil.copyProperties(d2,d);
            });
            return d;
        }).collect(Collectors.toList());

        xData = result.stream().map(item->{
            return  item.getName();
        }).collect(Collectors.toList());
        //移除null
        xData.removeAll(Collections.singleton(null));

        lData = dictDataVos.stream().map(item->{
            return  item.getRegionName();
        }).collect(Collectors.toList());

        List<Long> generallys = result.stream().map(item->{
            return item.getGenerallys();
        }).collect(Collectors.toList());

        List<Long> preciouses = result.stream().map(item->{
            return item.getPreciouses();
        }).collect(Collectors.toList());

        List<Long> larges = result.stream().map(item->{
            return item.getLarges();
        }).collect(Collectors.toList());

        List<Long> cars = result.stream().map(item->{
            return item.getCars();
        }).collect(Collectors.toList());


        yData.put("generallys",generallys);
        yData.put("preciouses",preciouses);
        yData.put("larges",larges);
        yData.put("cars",cars);



        data.put("xData",xData);
        data.put("yData",yData);
        data.put("lData",lData);
        return  data;
    }

    /**
     * 入库统计-右侧数据
     * @return
     */
    public Map<String,Object> statisticsWarehouseRight(){
        Map<String,Object> data = new HashMap<>();
        //横轴
        List<String> xData = new ArrayList<>();
        //竖轴

        List<DataVo> yData = new ArrayList<>();
        List<DataVo> result = new ArrayList<>();
        //过滤
//        List<Map<String,List<>>> lData = new ArrayList<>();

        //查询入库数据
        List<TaskDtlVo> taskDtlVos = iTaskDtlService.taskDtlDeptList();
        xData = taskDtlVos.stream().map(item->{
            return item.getDeptName();
        }).collect(Collectors.toList());

        List<TaskDtlVo> taskDtlDatas = iTaskDtlService.getDtlPropertyClassify(null);

        result = taskDtlDatas.stream().map(item->{
            DataVo vo = new DataVo();
            vo.setName(item.getThirdClassifyName());
            vo.setNums(item.getNums());
            vo.setType("line");
            vo.setStack("Total");
            vo.setSmooth(true);
            Map<String,String> emphasis = new HashMap<>();
            emphasis.put("focus","series");
            vo.setEmphasis(emphasis);
            return vo;
        }).collect(Collectors.toList());

        result = result.stream().filter(item->item.getName() != null).collect(Collectors.toList());

        Map<String,List<DataVo>> map = result.stream().collect(Collectors.groupingBy(DataVo::getName));
        for (Map.Entry<String, List<DataVo>> enty : map.entrySet()) {
            String key = enty.getKey();
            List<DataVo> valueList = enty.getValue();
            DataVo vo = new DataVo();
            BeanUtil.copyProperties(valueList.get(0),vo);

            List<Long> nums = valueList.stream().map(item->{return item.getNums();}).collect(Collectors.toList());
            vo.setData(nums);
            yData.add(vo);
        }

        data.put("xData",xData);
        data.put("yData",yData);
        return  data;
    }

    /**
     * 出库统计
     * @return
     */
    public Map<String,Object> statisticsExWarehouse(){
        Map<String,Object> data = new HashMap<>();
        //横轴
        List<String> xData = new ArrayList<>();
        //竖轴
        Map<String,List<Long>> yData = new HashMap<>();

        SysDictData dictData = new SysDictData();
        dictData.setDictType("wms_put_task_area");
        List<SysDictData> dictDataList = iSysDictDataService.selectDictDataList(dictData);

        List<TaskVo> taskVos = iTaskService.outTaskStatistics(new TaskBo());

        //taskVo转dataVo
        List<DataVo> taskData = taskVos.stream().map(item->{
            DataVo vo = new DataVo();
            vo.setRegion(item.getDictValue());
            vo.setRegionName(item.getDictLabel());
            vo.setGenerallys(item.getGenerallys());
            vo.setPreciouses(item.getPreciouses());
            vo.setLarges(item.getLarges());
            return  vo;
        }).collect(Collectors.toList());

        List<DataVo> dictDataVos = dictDataList.stream().map(item->{
            DataVo vo = new DataVo();
            vo.setRegion(item.getDictValue());
            vo.setRegionName(item.getDictLabel());
            vo.setGenerallys(0l);
            vo.setPreciouses(0l);
            vo.setLarges(0l);
            return vo;
        }).collect(Collectors.toList());

        //dataVos 合并到 dictDataVos
        List<DataVo> result = dictDataVos.stream().map(d->{
            taskData.stream().filter(d2->Objects.equals(d.getRegion(),d2.getRegion())).forEach(d2->{
                BeanUtil.copyProperties(d2,d);
            });
            return d;
        }).collect(Collectors.toList());


        //横轴数据处理
        xData = result.stream().map(item->{
            String region = null;
            if(item.getRegion().equals("QB")){
                region = null;
            }
            else if(item.getRegion().equals("SZ")){
                region = "市直";
            }
            else if(item.getRegion().equals("YA")){
                region = item.getRegionName()+"市";
            }
            else if(item.getRegion().equals("SY") || item.getRegion().equals("SX")){
                region = item.getRegionName()+"区";
            }
            else {
                region = item.getRegionName()+"县";
            }
            return region;
        }).collect(Collectors.toList());

        //竖轴数组处理
        List<Long> innums = result.stream().map(item->{
            Long count = null;
            if(!item.getRegion().equals("QB")){
                count = item.getGenerallys();
            }
            return count;
        }).collect(Collectors.toList());

        List<Long> outnums = result.stream().map(item->{
            Long count = null;
            if(!item.getRegion().equals("QB")){
                count = item.getPreciouses();
            }
            return count;
        }).collect(Collectors.toList());

        List<Long> deals = result.stream().map(item->{
            Long count = null;
            if(!item.getRegion().equals("QB")){
                count = item.getLarges();
            }
            return count;
        }).collect(Collectors.toList());

        //移除null
        xData.removeAll(Collections.singleton(null));
        innums.removeAll(Collections.singleton(null));
        deals.removeAll(Collections.singleton(null));
        outnums.removeAll(Collections.singleton(null));

        yData.put("innums",innums);
        yData.put("outnums",outnums);
        yData.put("deals",deals);

        data.put("xData",xData);
        data.put("yData",yData);
        return  data;
    }

    /**
     * 订单统计
     * @return
     */
    public Map<String,Object> statisticsOrder(){
        Map<String,Object> data = new HashMap<>();
        //横轴
        List<String> xData = new ArrayList<>();
        //竖轴
        Map<String,List<Long>> yData = new HashMap<>();

        String[] dateList = new String[]{"1","2","3","4","5","6","7","8","9","10","11","12"};
        List<String> dates = Arrays.asList(dateList);
        xData = dates.stream().map(date->{
            return date+"月";
        }).collect(Collectors.toList());

        List<OrderVo> orderVos = iOrderService.orderStatistics();

        List<DataVo> orderData = orderVos.stream().map(item->{
            DataVo vo = new DataVo();
            vo.setMonths(item.getMonths());
            vo.setWarehouseNums(item.getWarehouseNums());
            vo.setExWarehouseNums(item.getExWarehouseNums());
            vo.setTransferNums(item.getTransferNums());
            vo.setDealNums(item.getDealNums());
            vo.setNums(item.getNums());
            return vo;
        }).collect(Collectors.toList());

        List<DataVo> dataVos = dates.stream().map(item->{
            DataVo vo = new DataVo();
            vo.setMonths(item);
            vo.setWarehouseNums(0l);
            vo.setExWarehouseNums(0l);
            vo.setTransferNums(0l);
            vo.setDealNums(0l);
            vo.setNums(0l);

            return vo;
        }).collect(Collectors.toList());

        //dataVos 合并到 dictDataVos
        List<DataVo> result = dataVos.stream().map(d->{
            orderData.stream().filter(d2->Objects.equals(d.getMonths(),d2.getMonths())).forEach(d2->{
                BeanUtil.copyProperties(d2,d);
            });
            return d;
        }).collect(Collectors.toList());

        List<Long> warehouseNums = result.stream().map(item->{
            return item.getWarehouseNums();
        }).collect(Collectors.toList());

        List<Long> exWarehouseNums = result.stream().map(item->{
            return item.getExWarehouseNums();
        }).collect(Collectors.toList());

        List<Long> transferNums = result.stream().map(item->{
            return item.getTransferNums();
        }).collect(Collectors.toList());

        List<Long> dealNums = result.stream().map(item->{
            return item.getDealNums();
        }).collect(Collectors.toList());

        List<Long> nums = result.stream().map(item->{
            return item.getNums();
        }).collect(Collectors.toList());

        yData.put("warehouseNums",warehouseNums);
        yData.put("exWarehouseNums",exWarehouseNums);
        yData.put("transferNums",transferNums);
        yData.put("dealNums",dealNums);
        yData.put("nums",nums);


        data.put("xData",xData);
        data.put("yData",yData);
        return  data;
    }


    /**
     * 运单统计
     * @return
     */
    public Map<String,Object> statisticsWaybill(){
        Map<String,Object> data = new HashMap<>();
        //横轴
        List<String> xData = new ArrayList<>();
        //竖轴
        List<DataVo> yData = new ArrayList<>();

        String[] dateList = new String[]{"1","2","3","4","5","6","7","8","9","10","11","12"};
        List<String> dates = Arrays.asList(dateList);
        xData = dates.stream().map(date->{
            return date+"月";
        }).collect(Collectors.toList());

        List<DataVo> dataVos = dates.stream().map(item->{
            DataVo vo = new DataVo();
            vo.setMonths(item);
            return vo;
        }).collect(Collectors.toList());

        List<DataVo> waybillData = new ArrayList<>();
        List<WaybillVo> waybillVos = iWaybillService.waybillStatistics();
        Map<String,List<WaybillVo>> map = waybillVos.stream().collect(Collectors.groupingBy(WaybillVo::getDictValue));
        for (Map.Entry<String, List<WaybillVo>> enty : map.entrySet()) {
            String key = enty.getKey();
            List<WaybillVo> valueList = enty.getValue();
            DataVo vo = new DataVo();

            vo.setRegion(key);
            vo.setName(valueList.get(0).getDictLabel());

            List<Long> counts = dates.stream().map(item->{
                Long count = 0l;
                for (WaybillVo waybillVo:valueList){
                    if(waybillVo.getMonth().equals(item)){
                        count = waybillVo.getNums().longValue();
                    }
                }
                return count;
            }).collect(Collectors.toList());
            vo.setData(counts);
            vo.setType("line");
            waybillData.add(vo);
        }


        SysDictData dictData = new SysDictData();
        dictData.setDictType("wms_put_task_area");
        List<SysDictData> dictDataList = iSysDictDataService.selectDictDataList(dictData);

        List<DataVo> dictDataVos = dictDataList.stream().map(item->{
            DataVo vo = new DataVo();
            vo.setRegion(item.getDictValue());
            vo.setName(item.getDictLabel());
            List<Long> datas = new ArrayList<>();
            for (int i = 0;i<12;i++){
                datas.add(0l);
            }
            vo.setData(datas);
            vo.setType("line");
            return vo;
        }).collect(Collectors.toList());


        //dataVos 合并到 dictDataVos
        yData = dictDataVos.stream().map(d->{
            waybillData.stream().filter(d2->Objects.equals(d.getRegion(),d2.getRegion())).forEach(d2->{
                BeanUtil.copyProperties(d2,d);
            });
            return d;
        }).collect(Collectors.toList());

        yData = yData.stream().filter(item-> !item.getRegion().equals("QB")).collect(Collectors.toList());

        data.put("xData",xData);
        data.put("yData",yData);
        return  data;
    }

    @GetMapping("/report")
    public Map<String,Object> report(InventoryBo bo){
        Map<String,Object> data = new HashMap<>();
        //横轴
        SysDictData dictData = new SysDictData();
        dictData.setDictType("wms_put_task_area");
        List<SysDictData> dictDataList = iSysDictDataService.selectDictDataList(dictData);
        List<String> xData = dictDataList.stream().map(item->item.getDictLabel()).collect(Collectors.toList());

        //仓库报表
        List<StoreBiVo> stores = iInventoryService.selectCountByStore(bo,dictDataList);
        data.put("stores",stores);
        Map<String,Object> storeResult = new HashMap<>();

        storeResult = getStoreResult(dictDataList,stores,storeResult);

        //库区报表
        List<AreaBiVo> areas = iInventoryService.selectCountByArea(bo);
        data.put("areas",areas);
        Map<String,Object> areaResult = new HashMap<>();

        areaResult = getAreaResult(dictDataList,areas,areaResult);

        //地区报表
        List<RegionBiVo> regions = iInventoryService.selectCountByRegion(bo);
        data.put("regions",regions);
        Map<String,Object> regionResult = new HashMap<>();

        regionResult = getRegionResult(dictDataList,regions,regionResult);

        data.put("xData",xData);
        data.put("storeResult",storeResult);
        data.put("areaResult",areaResult);
        data.put("regionResult",regionResult);
        if(StringUtils.isEmpty(bo.getStoreId())){
            bo.setStoreId("f2060d9fd9814f0e88a8a898c45a7cba");
            data.put("carTypeResult",iInventoryService.selectCountByCarType(bo));
        }else if(!StringUtils.isEmpty(bo.getStoreId()) && bo.getStoreId().equals("f2060d9fd9814f0e88a8a898c45a7cba")){
            data.put("carTypeResult",iInventoryService.selectCountByCarType(bo));
        }
        return  data;
    }

    @GetMapping("/reportv2")
    public Map<String,Object> reportv2(InventoryBo bo){
        Map<String,Object> data = new HashMap<>();
        //横轴
        SysDictData dictData = new SysDictData();
        dictData.setDictType("wms_put_task_area");
        List<SysDictData> dictDataList = iSysDictDataService.selectDictDataList(dictData);
        List<String> xData = dictDataList.stream().map(item->item.getDictLabel()).collect(Collectors.toList());

        //仓库报表
        List<StoreBiVo> stores = iInventoryService.selectCountByStore(bo,dictDataList);
        data.put("stores",stores);

        //仓库报表
        List<StoreBiVo> storesApp = iInventoryService.selectCountByStoreApp(bo);
        data.put("storesApp",storesApp);

        Map<String,Object> storeResult = new HashMap<>();

        Map<String,Object> storeAppResult = new HashMap<>();

        storeResult = getStoreResult(dictDataList,stores,storeResult);

        storeAppResult = getStoreResult(dictDataList,storesApp,storeAppResult);

        //库区报表
        List<AreaBiVo> areas = iInventoryService.selectCountByArea(bo);
        data.put("areas",areas);
        Map<String,Object> areaResult = new HashMap<>();

        areaResult = getAreaResult(dictDataList,areas,areaResult);

        //地区报表
        List<RegionBiVo> regions = iInventoryService.selectCountByRegion(bo);
        data.put("regions",regions);

        List<RegionBiVo> regionsApp = iInventoryService.selectCountByRegionApp(bo);
        data.put("regionsApp",regionsApp);

        Map<String,Object> regionResult = new HashMap<>();

        Map<String,Object> regionAppResult = new HashMap<>();

        regionResult = getRegionResult(dictDataList,regions,regionResult);

        regionAppResult = getRegionResult(dictDataList,regionsApp,regionAppResult);

        data.put("xData",xData);
        data.put("storeResult",storeResult);
        data.put("storeAppResult",storeAppResult);
        data.put("areaResult",areaResult);
        data.put("regionResult",regionResult);
        data.put("regionAppResult",regionAppResult);
        return  data;
    }

    @GetMapping("/weekReport")
    public R<Map<String,Object>> weekReport(InventoryBo bo) throws ParseException {
        Map<String,Object> data = new HashMap<>();

        String MonDay = DateUtils.getWeekMonDay(DateUtils.date2String(new Date()));
        String SunDay = DateUtils.getWeekSunDay(DateUtils.date2String(new Date()));

        Long receives = 0l;
        Long outs = 0l;
        Long transfers = 0l;
        Long deals = 0l;
        Long reverts = 0l;
        Long eouts = 0l;
        Long etransfers = 0l;

        //本周接收
        TaskBo taskBo = new TaskBo();
        taskBo.setWeekStarts(MonDay);
        taskBo.setWeekEnds(SunDay);
        taskBo.setType("0");
        Map<String,Object> receiveTask = iTaskService.countWeekWithTask(taskBo);
        if(receiveTask != null){
            Long pickups = (receiveTask.get("PICKUPS") != null && !StringUtils.isEmpty(receiveTask.get("PICKUPS").toString())) ? Long.parseLong(receiveTask.get("PICKUPS").toString()) : 0;
            Long deliverys = (receiveTask.get("DELIVERYS") != null && !StringUtils.isEmpty(receiveTask.get("DELIVERYS").toString())) ? Long.parseLong(receiveTask.get("DELIVERYS").toString()) : 0;
            receives = pickups + deliverys;
        }

        //本周出库
        taskBo.setType("1");
        taskBo.setEvidence("0");
        Map<String,Object> outsTask = iTaskService.countWeekWithTask(taskBo);
        if(outsTask != null){
            Long pickups = (outsTask.get("PICKUPS") != null && !StringUtils.isEmpty(outsTask.get("PICKUPS").toString())) ? Long.parseLong(outsTask.get("PICKUPS").toString()) : 0;
            Long deliverys = (outsTask.get("DELIVERYS") != null && !StringUtils.isEmpty(outsTask.get("DELIVERYS").toString())) ? Long.parseLong(outsTask.get("DELIVERYS").toString()) : 0;
            outs = pickups + deliverys;
        }

        //本周取证出库
        taskBo.setType("1");
        taskBo.setEvidence("1");
        Map<String,Object> eoutsTask = iTaskService.countWeekWithTask(taskBo);
        if(eoutsTask != null){
            Long pickups = (eoutsTask.get("PICKUPS") != null && !StringUtils.isEmpty(eoutsTask.get("PICKUPS").toString())) ? Long.parseLong(eoutsTask.get("PICKUPS").toString()) : 0;
            Long deliverys = (eoutsTask.get("DELIVERYS") != null && !StringUtils.isEmpty(eoutsTask.get("DELIVERYS").toString())) ? Long.parseLong(eoutsTask.get("DELIVERYS").toString()) : 0;
            eouts = pickups + deliverys;
        }


        //本周调用
        taskBo.setType("3");
        taskBo.setEvidence("0");
        Map<String,Object> transfersTask = iTaskService.countWeekWithTask(taskBo);
        if(transfersTask != null){
            Long pickups = (transfersTask.get("PICKUPS") != null && !StringUtils.isEmpty(transfersTask.get("PICKUPS").toString())) ? Long.parseLong(transfersTask.get("PICKUPS").toString()) : 0;
            Long deliverys = (transfersTask.get("DELIVERYS") != null && !StringUtils.isEmpty(transfersTask.get("DELIVERYS").toString())) ? Long.parseLong(transfersTask.get("DELIVERYS").toString()) : 0;
            transfers = pickups + deliverys;
        }

        //本周取证调用
        taskBo.setType("3");
        taskBo.setEvidence("1");
        Map<String,Object> etransfersTask = iTaskService.countWeekWithTask(taskBo);
        if(etransfersTask != null){
            Long pickups = (etransfersTask.get("PICKUPS") != null && !StringUtils.isEmpty(etransfersTask.get("PICKUPS").toString())) ? Long.parseLong(etransfersTask.get("PICKUPS").toString()) : 0;
            Long deliverys = (etransfersTask.get("DELIVERYS") != null && !StringUtils.isEmpty(etransfersTask.get("DELIVERYS").toString())) ? Long.parseLong(etransfersTask.get("DELIVERYS").toString()) : 0;
            etransfers = pickups + deliverys;
        }

        //本周处置
        taskBo.setType("2");
        Map<String,Object> dealsTask = iTaskService.countWeekWithTask(taskBo);
        if(dealsTask != null){
            Long pickups = (dealsTask.get("PICKUPS") != null && !StringUtils.isEmpty(dealsTask.get("PICKUPS").toString())) ? Long.parseLong(dealsTask.get("PICKUPS").toString()) : 0;
            Long deliverys =(dealsTask.get("DELIVERYS") != null && !StringUtils.isEmpty(dealsTask.get("DELIVERYS").toString())) ?  Long.parseLong(dealsTask.get("DELIVERYS").toString()) : 0;
            deals = pickups + deliverys;
        }

        //本周归还
        taskBo.setType("1");
        taskBo.setIsReturn(true);
        Map<String,Object> revertsTask = iTaskService.countWeekWithTask(taskBo);
        if(revertsTask != null){
            Long pickups = (revertsTask.get("PICKUPS") != null && !StringUtils.isEmpty(revertsTask.get("PICKUPS").toString())) ? Long.parseLong(revertsTask.get("PICKUPS").toString()) : 0;
            Long deliverys = (revertsTask.get("DELIVERYS") != null && !StringUtils.isEmpty(revertsTask.get("DELIVERYS").toString())) ? Long.parseLong(revertsTask.get("DELIVERYS").toString()) : 0;
            reverts = pickups + deliverys;
        }

        data.put("receives",receives);
        data.put("outs",outs);
        data.put("transfers",transfers);
        data.put("deals",deals);
        data.put("reverts",reverts);
        data.put("eouts",eouts);
        data.put("etransfers",etransfers);

        return R.ok(data);
    }

    private Map<String,Object> getStoreResult(List<SysDictData> dictDataList,List<StoreBiVo> stores,Map<String,Object> storeResult){
        List<Long> alls = new ArrayList<>();
        List<Long> cars = new ArrayList<>();
        List<Long> innums = new ArrayList<>();
        List<Long> outnums = new ArrayList<>();
        List<Long> deals = new ArrayList<>();
        List<Long> tnums = new ArrayList<>();
        List<Long> rnums = new ArrayList<>();
        List<Long> nums = new ArrayList<>();
        List<Long> eoutnums = new ArrayList<>();
        List<Long> etnums = new ArrayList<>();

        List<StoreBiVo> dictDataVos = dictDataList.stream().map(item->{
            StoreBiVo vo = new StoreBiVo();
            vo.setStoreName(null);
            vo.setRegion(item.getDictValue());
            vo.setInnums(0l);
            vo.setOutnums(0l);
            vo.setDeals(0l);
            vo.setTnums(0l);
            vo.setRnums(0l);
            vo.setNums(0l);
            vo.setEoutnums(0l);
            vo.setEtnums(0l);
            return vo;
        }).collect(Collectors.toList());

        List<StoreBiVo> zhDatas = stores.stream().filter(d->d.getStoreName().equals("综合仓")).collect(Collectors.toList());
        List<StoreBiVo> clDatas = stores.stream().filter(d->d.getStoreName().equals("车辆仓")).collect(Collectors.toList());

        List<StoreBiVo> storeZHResultVos = dictDataVos.stream().map(d->{
            StoreBiVo dvo = BeanUtil.copyProperties(d,StoreBiVo.class);
            zhDatas.stream().filter(d2->Objects.equals(d.getRegion(),d2.getRegion())).forEach(d2->{
                BeanUtil.copyProperties(d2,dvo);
            });
            return dvo;
        }).collect(Collectors.toList());
        List<StoreBiVo> storeCLResultVos = dictDataVos.stream().map(d->{
            StoreBiVo dvo = BeanUtil.copyProperties(d,StoreBiVo.class);
            clDatas.stream().filter(d2->Objects.equals(d.getRegion(),d2.getRegion())).forEach(d2->{
                BeanUtil.copyProperties(d2,dvo);
            });
            return dvo;
        }).collect(Collectors.toList());

        alls = storeZHResultVos.stream().map(item->{
            Long allsNum = 0l;
            if(StringUtils.isNotEmpty(item.getStoreName()) && item.getStoreName().equals("综合仓")){
                allsNum = item.getNums();
            }
            return allsNum;
        }).collect(Collectors.toList());
        cars = storeCLResultVos.stream().map(item->{
            Long carsNum = 0l;
            if(StringUtils.isNotEmpty(item.getStoreName()) && item.getStoreName().equals("车辆仓")){
                carsNum = item.getNums();
            }
            return carsNum;
        }).collect(Collectors.toList());
        List<StoreBiVo> arr1 = storeZHResultVos;
        List<StoreBiVo> arr2 = storeCLResultVos;

        List<StoreBiVo> storeResultVos = IntStream.range(0, arr1.size())
            .mapToObj(i -> {
                StoreBiVo ivo = BeanUtil.copyProperties(arr1.get(i),StoreBiVo.class);
                ivo.setNums((arr1.get(i).getNums() != null?arr1.get(i).getNums():0)+(arr2.get(i).getNums() != null ? arr2.get(i).getNums() : 0));
                ivo.setInnums((arr1.get(i).getInnums() != null?arr1.get(i).getInnums():0)+(arr2.get(i).getInnums() != null ? arr2.get(i).getInnums() : 0));
                ivo.setOutnums((arr1.get(i).getOutnums() != null?arr1.get(i).getOutnums():0)+(arr2.get(i).getOutnums() != null ? arr2.get(i).getOutnums() : 0));
                ivo.setDeals((arr1.get(i).getDeals() != null?arr1.get(i).getDeals():0)+(arr2.get(i).getDeals() != null ? arr2.get(i).getDeals() : 0));
                ivo.setTnums((arr1.get(i).getTnums() != null?arr1.get(i).getTnums():0)+(arr2.get(i).getTnums() != null ? arr2.get(i).getTnums() : 0));
                ivo.setRnums((arr1.get(i).getRnums() != null?arr1.get(i).getRnums():0)+(arr2.get(i).getRnums() != null ? arr2.get(i).getRnums() : 0));
                ivo.setEoutnums((arr1.get(i).getEoutnums() != null?arr1.get(i).getEoutnums():0)+(arr2.get(i).getEoutnums() != null ? arr2.get(i).getEoutnums() : 0));
                ivo.setEtnums((arr1.get(i).getEtnums() != null?arr1.get(i).getEtnums():0)+(arr2.get(i).getEtnums() != null ? arr2.get(i).getEtnums() : 0));
                return ivo;
            })
            .collect(Collectors.toList());

        innums = storeResultVos.stream().map(item->{return item.getInnums() != null? item.getInnums() : 0;}).collect(Collectors.toList());
        outnums = storeResultVos.stream().map(item->{return item.getOutnums() != null? item.getOutnums() : 0;}).collect(Collectors.toList());
        deals = storeResultVos.stream().map(item->{return item.getDeals() != null? item.getDeals() : 0;}).collect(Collectors.toList());
        tnums = storeResultVos.stream().map(item->{return item.getTnums() != null? item.getTnums() : 0;}).collect(Collectors.toList());
        rnums = storeResultVos.stream().map(item->{return item.getRnums() != null? item.getRnums() : 0;}).collect(Collectors.toList());
        nums = storeResultVos.stream().map(item->{return item.getNums() != null? item.getNums() : 0;}).collect(Collectors.toList());
        eoutnums = storeResultVos.stream().map(item->{return item.getEoutnums() != null? item.getEoutnums() : 0;}).collect(Collectors.toList());
        etnums = storeResultVos.stream().map(item->{return item.getEtnums() != null? item.getEtnums() : 0;}).collect(Collectors.toList());

        alls.set(0,alls.stream().mapToLong(number-> number).sum());
        cars.set(0,cars.stream().mapToLong(number-> number).sum());
        innums.set(0,innums.stream().mapToLong(number-> number).sum());
        outnums.set(0,outnums.stream().mapToLong(number-> number).sum());
        deals.set(0,deals.stream().mapToLong(number-> number).sum());
        tnums.set(0,tnums.stream().mapToLong(number-> number).sum());
        rnums.set(0,rnums.stream().mapToLong(number-> number).sum());
        nums.set(0,nums.stream().mapToLong(number-> number).sum());
        eoutnums.set(0,eoutnums.stream().mapToLong(number-> number).sum());
        etnums.set(0,etnums.stream().mapToLong(number-> number).sum());

        storeResult.put("alls",alls);
        storeResult.put("cars",cars);
        storeResult.put("innums",innums);
        storeResult.put("outnums",outnums);
        storeResult.put("deals",deals);
        storeResult.put("tnums",tnums);
        storeResult.put("rnums",rnums);
        storeResult.put("nums",nums);
        storeResult.put("eoutnums",eoutnums);
        storeResult.put("etnums",etnums);

        return storeResult;
    }

    private Map<String,Object> getAreaResult(List<SysDictData> dictDataList, List<AreaBiVo> areas, Map<String,Object> areaResult){
        List<Long> clnums = new ArrayList<>();
        List<Long> dxnums = new ArrayList<>();
        List<Long> ptnums = new ArrayList<>();
        List<Long> gznums = new ArrayList<>();
        List<Long> dznums = new ArrayList<>();
        List<Long> zxnums = new ArrayList<>();
        List<Long> innums = new ArrayList<>();
        List<Long> outnums = new ArrayList<>();
        List<Long> deals = new ArrayList<>();
        List<Long> tnums = new ArrayList<>();
        List<Long> rnums = new ArrayList<>();
        List<Long> nums = new ArrayList<>();
        List<Long> eoutnums = new ArrayList<>();
        List<Long> etnums = new ArrayList<>();

        List<AreaBiVo> dictDataVos = dictDataList.stream().map(item->{
            AreaBiVo vo = new AreaBiVo();
            vo.setAreaName(null);
            vo.setRegion(item.getDictValue());
            vo.setInnums(0l);
            vo.setOutnums(0l);
            vo.setDeals(0l);
            vo.setTnums(0l);
            vo.setRnums(0l);
            vo.setNums(0l);
            vo.setEoutnums(0l);
            vo.setEtnums(0l);
            return vo;
        }).collect(Collectors.toList());

        List<AreaBiVo> clDatas = areas.stream().filter(d->d.getAreaNo().equals("CL")).collect(Collectors.toList());
        List<AreaBiVo> dxDatas = areas.stream().filter(d->d.getAreaNo().equals("DX")).collect(Collectors.toList());
        List<AreaBiVo> ptDatas = areas.stream().filter(d->d.getAreaNo().equals("PT")).collect(Collectors.toList());
        List<AreaBiVo> gzDatas = areas.stream().filter(d->d.getAreaNo().equals("GZ")).collect(Collectors.toList());
        List<AreaBiVo> dzDatas = areas.stream().filter(d->d.getAreaNo().equals("DZ")).collect(Collectors.toList());
        List<AreaBiVo> zxDatas = areas.stream().filter(d->d.getAreaNo().equals("ZX")).collect(Collectors.toList());

        List<AreaBiVo> clResultVos = dictDataVos.stream().map(d->{
            AreaBiVo dvo = BeanUtil.copyProperties(d,AreaBiVo.class);
            clDatas.stream().filter(d2->Objects.equals(d.getRegion(),d2.getRegion())).forEach(d2->{ BeanUtil.copyProperties(d2,dvo); }); return dvo;
        }).collect(Collectors.toList());

        List<AreaBiVo> dxResultVos = dictDataVos.stream().map(d->{
            AreaBiVo dvo = BeanUtil.copyProperties(d,AreaBiVo.class);
            dxDatas.stream().filter(d2->Objects.equals(d.getRegion(),d2.getRegion())).forEach(d2->{ BeanUtil.copyProperties(d2,dvo); }); return dvo;
        }).collect(Collectors.toList());

        List<AreaBiVo> ptResultVos = dictDataVos.stream().map(d->{
            AreaBiVo dvo = BeanUtil.copyProperties(d,AreaBiVo.class);
            ptDatas.stream().filter(d2->Objects.equals(d.getRegion(),d2.getRegion())).forEach(d2->{ BeanUtil.copyProperties(d2,dvo); }); return dvo;
        }).collect(Collectors.toList());

        List<AreaBiVo> gzResultVos = dictDataVos.stream().map(d->{
            AreaBiVo dvo = BeanUtil.copyProperties(d,AreaBiVo.class);
            gzDatas.stream().filter(d2->Objects.equals(d.getRegion(),d2.getRegion())).forEach(d2->{ BeanUtil.copyProperties(d2,dvo); }); return dvo;
        }).collect(Collectors.toList());

        List<AreaBiVo> dzResultVos = dictDataVos.stream().map(d->{
            AreaBiVo dvo = BeanUtil.copyProperties(d,AreaBiVo.class);
            dzDatas.stream().filter(d2->Objects.equals(d.getRegion(),d2.getRegion())).forEach(d2->{ BeanUtil.copyProperties(d2,dvo); }); return dvo;
        }).collect(Collectors.toList());

        List<AreaBiVo> zxResultVos = dictDataVos.stream().map(d->{
            AreaBiVo dvo = BeanUtil.copyProperties(d,AreaBiVo.class);
            zxDatas.stream().filter(d2->Objects.equals(d.getRegion(),d2.getRegion())).forEach(d2->{ BeanUtil.copyProperties(d2,dvo); }); return dvo;
        }).collect(Collectors.toList());


        List<AreaBiVo> areaResultVos = IntStream.range(0, clResultVos.size())
            .mapToObj(i -> {
                AreaBiVo ivo = BeanUtil.copyProperties(clResultVos.get(i),AreaBiVo.class);
                ivo.setNums(
                    (clResultVos.get(i).getNums() != null ? clResultVos.get(i).getNums():0)+
                    (dxResultVos.get(i).getNums() != null ? dxResultVos.get(i).getNums():0)+
                    (ptResultVos.get(i).getNums() != null ? ptResultVos.get(i).getNums():0)+
                    (gzResultVos.get(i).getNums() != null ? gzResultVos.get(i).getNums():0)+
                    (dzResultVos.get(i).getNums() != null ? dzResultVos.get(i).getNums():0)+
                    (zxResultVos.get(i).getNums() != null ? zxResultVos.get(i).getNums():0)
                );
                ivo.setInnums(
                    (clResultVos.get(i).getInnums() != null ? clResultVos.get(i).getInnums():0)+
                        (dxResultVos.get(i).getInnums() != null ? dxResultVos.get(i).getInnums():0)+
                        (ptResultVos.get(i).getInnums() != null ? ptResultVos.get(i).getInnums():0)+
                        (gzResultVos.get(i).getInnums() != null ? gzResultVos.get(i).getInnums():0)+
                        (dzResultVos.get(i).getInnums() != null ? dzResultVos.get(i).getInnums():0)+
                        (zxResultVos.get(i).getInnums() != null ? zxResultVos.get(i).getInnums():0)
                );
                ivo.setOutnums(
                    (clResultVos.get(i).getOutnums() != null ? clResultVos.get(i).getOutnums():0)+
                        (dxResultVos.get(i).getOutnums() != null ? dxResultVos.get(i).getOutnums():0)+
                        (ptResultVos.get(i).getOutnums() != null ? ptResultVos.get(i).getOutnums():0)+
                        (gzResultVos.get(i).getOutnums() != null ? gzResultVos.get(i).getOutnums():0)+
                        (dzResultVos.get(i).getOutnums() != null ? dzResultVos.get(i).getOutnums():0)+
                        (zxResultVos.get(i).getOutnums() != null ? zxResultVos.get(i).getOutnums():0)
                );
                ivo.setDeals(
                    (clResultVos.get(i).getDeals() != null ? clResultVos.get(i).getDeals():0)+
                        (dxResultVos.get(i).getDeals() != null ? dxResultVos.get(i).getDeals():0)+
                        (ptResultVos.get(i).getDeals() != null ? ptResultVos.get(i).getDeals():0)+
                        (gzResultVos.get(i).getDeals() != null ? gzResultVos.get(i).getDeals():0)+
                        (dzResultVos.get(i).getDeals() != null ? dzResultVos.get(i).getDeals():0)+
                        (zxResultVos.get(i).getDeals() != null ? zxResultVos.get(i).getDeals():0)
                );
                ivo.setTnums(
                    (clResultVos.get(i).getTnums() != null ? clResultVos.get(i).getTnums():0)+
                        (dxResultVos.get(i).getTnums() != null ? dxResultVos.get(i).getTnums():0)+
                        (ptResultVos.get(i).getTnums() != null ? ptResultVos.get(i).getTnums():0)+
                        (gzResultVos.get(i).getTnums() != null ? gzResultVos.get(i).getTnums():0)+
                        (dzResultVos.get(i).getTnums() != null ? dzResultVos.get(i).getTnums():0)+
                        (zxResultVos.get(i).getTnums() != null ? zxResultVos.get(i).getTnums():0)
                );
                ivo.setRnums(
                    (clResultVos.get(i).getRnums() != null ? clResultVos.get(i).getRnums():0)+
                        (dxResultVos.get(i).getRnums() != null ? dxResultVos.get(i).getRnums():0)+
                        (ptResultVos.get(i).getRnums() != null ? ptResultVos.get(i).getRnums():0)+
                        (gzResultVos.get(i).getRnums() != null ? gzResultVos.get(i).getRnums():0)+
                        (dzResultVos.get(i).getRnums() != null ? dzResultVos.get(i).getRnums():0)+
                        (zxResultVos.get(i).getRnums() != null ? zxResultVos.get(i).getRnums():0)
                );
                ivo.setEoutnums(
                    (clResultVos.get(i).getEoutnums() != null ? clResultVos.get(i).getEoutnums():0)+
                        (dxResultVos.get(i).getEoutnums() != null ? dxResultVos.get(i).getEoutnums():0)+
                        (ptResultVos.get(i).getEoutnums() != null ? ptResultVos.get(i).getEoutnums():0)+
                        (gzResultVos.get(i).getEoutnums() != null ? gzResultVos.get(i).getEoutnums():0)+
                        (dzResultVos.get(i).getEoutnums() != null ? dzResultVos.get(i).getEoutnums():0)+
                        (zxResultVos.get(i).getEoutnums() != null ? zxResultVos.get(i).getEoutnums():0)
                );
                ivo.setEtnums(
                    (clResultVos.get(i).getEtnums() != null ? clResultVos.get(i).getEtnums():0)+
                        (dxResultVos.get(i).getEtnums() != null ? dxResultVos.get(i).getEtnums():0)+
                        (ptResultVos.get(i).getEtnums() != null ? ptResultVos.get(i).getEtnums():0)+
                        (gzResultVos.get(i).getEtnums() != null ? gzResultVos.get(i).getEtnums():0)+
                        (dzResultVos.get(i).getEtnums() != null ? dzResultVos.get(i).getEtnums():0)+
                        (zxResultVos.get(i).getEtnums() != null ? zxResultVos.get(i).getEtnums():0)
                );
                return ivo;
            })
            .collect(Collectors.toList());


//        List<AreaBiVo> areaResultVos = dictDataVos.stream().map(d->{
//            areas.stream().filter(d2->Objects.equals(d.getRegion(),d2.getRegion())).forEach(d2->{
//                BeanUtil.copyProperties(d2,d);
//            });
//            return d;
//        }).collect(Collectors.toList());

        clnums = clResultVos.stream().map(item->{ return item.getNums(); }).collect(Collectors.toList());

        dxnums = dxResultVos.stream().map(item->{ return item.getNums(); }).collect(Collectors.toList());

        ptnums = ptResultVos.stream().map(item->{ return item.getNums(); }).collect(Collectors.toList());

        gznums = gzResultVos.stream().map(item->{ return item.getNums(); }).collect(Collectors.toList());

        dznums = dzResultVos.stream().map(item->{ return item.getNums(); }).collect(Collectors.toList());

        zxnums = zxResultVos.stream().map(item->{ return item.getNums(); }).collect(Collectors.toList());

        innums = areaResultVos.stream().map(item->{return item.getInnums()!= null ? item.getInnums() : 0;}).collect(Collectors.toList());
        outnums = areaResultVos.stream().map(item->{return item.getOutnums() != null ? item.getOutnums() : 0;}).collect(Collectors.toList());
        deals = areaResultVos.stream().map(item->{return item.getDeals() != null ? item.getDeals() : 0;}).collect(Collectors.toList());
        tnums = areaResultVos.stream().map(item->{return item.getTnums() != null ? item.getTnums() : 0;}).collect(Collectors.toList());
        rnums = areaResultVos.stream().map(item->{return item.getRnums() != null ? item.getRnums() : 0;}).collect(Collectors.toList());
        nums = areaResultVos.stream().map(item->{return item.getNums() != null ? item.getNums() : 0;}).collect(Collectors.toList());
        eoutnums = areaResultVos.stream().map(item->{return item.getEoutnums() != null ? item.getEoutnums() : 0;}).collect(Collectors.toList());
        etnums = areaResultVos.stream().map(item->{return item.getEtnums() != null ? item.getEtnums() : 0;}).collect(Collectors.toList());

        clnums.set(0,clnums.stream().mapToLong(number-> number).sum());
        dxnums.set(0,dxnums.stream().mapToLong(number-> number).sum());
        ptnums.set(0,ptnums.stream().mapToLong(number-> number).sum());
        gznums.set(0,gznums.stream().mapToLong(number-> number).sum());
        dznums.set(0,dznums.stream().mapToLong(number-> number).sum());
        zxnums.set(0,zxnums.stream().mapToLong(number-> number).sum());

        innums.set(0,innums.stream().mapToLong(number-> number).sum());
        outnums.set(0,outnums.stream().mapToLong(number-> number).sum());
        deals.set(0,deals.stream().mapToLong(number-> number).sum());
        tnums.set(0,tnums.stream().mapToLong(number-> number).sum());
        rnums.set(0,rnums.stream().mapToLong(number-> number).sum());
        nums.set(0,nums.stream().mapToLong(number-> number).sum());
        eoutnums.set(0,eoutnums.stream().mapToLong(number-> number).sum());
        etnums.set(0,etnums.stream().mapToLong(number-> number).sum());


        areaResult.put("clnums",clnums);
        areaResult.put("dxnums",dxnums);
        areaResult.put("ptnums",ptnums);
        areaResult.put("gznums",gznums);
        areaResult.put("dznums",dznums);
        areaResult.put("zxnums",zxnums);
        areaResult.put("innums",innums);
        areaResult.put("outnums",outnums);
        areaResult.put("deals",deals);
        areaResult.put("tnums",tnums);
        areaResult.put("rnums",rnums);
        areaResult.put("nums",nums);
        areaResult.put("eoutnums",eoutnums);
        areaResult.put("etnums",etnums);

        return areaResult;
    }

    private Map<String,Object> getRegionResult(List<SysDictData> dictDataList, List<RegionBiVo> regions, Map<String,Object> regionResult){
        List<Long> innums = new ArrayList<>();
        List<Long> outnums = new ArrayList<>();
        List<Long> deals = new ArrayList<>();
        List<Long> tnums = new ArrayList<>();
        List<Long> rnums = new ArrayList<>();
        List<Long> nums = new ArrayList<>();
        List<Long> eoutnums = new ArrayList<>();
        List<Long> etnums = new ArrayList<>();

        List<RegionBiVo> dictDataVos = dictDataList.stream().map(item->{
            RegionBiVo vo = new RegionBiVo();
            vo.setRegion(item.getDictValue());
            vo.setInnums(0l);
            vo.setOutnums(0l);
            vo.setDeals(0l);
            vo.setTnums(0l);
            vo.setRnums(0l);
            vo.setNums(0l);
            vo.setEoutnums(0l);
            vo.setEtnums(0l);
            return vo;
        }).collect(Collectors.toList());

        List<RegionBiVo> regionResultVos = dictDataVos.stream().map(d->{
            regions.stream().filter(d2->Objects.equals(d.getRegion(),d2.getRegion())).forEach(d2->{
                BeanUtil.copyProperties(d2,d);
            });
            return d;
        }).collect(Collectors.toList());

        innums = regionResultVos.stream().map(item->{return item.getInnums() !=null ? item.getInnums() : 0;}).collect(Collectors.toList());
        outnums = regionResultVos.stream().map(item->{return item.getOutnums() !=null ? item.getOutnums() : 0;}).collect(Collectors.toList());
        deals = regionResultVos.stream().map(item->{return item.getDeals() !=null ? item.getDeals() : 0;}).collect(Collectors.toList());
        tnums = regionResultVos.stream().map(item->{return item.getTnums() !=null ? item.getTnums() : 0;}).collect(Collectors.toList());
        rnums = regionResultVos.stream().map(item->{return item.getRnums() !=null ? item.getRnums() : 0;}).collect(Collectors.toList());
        nums = regionResultVos.stream().map(item->{return item.getNums() !=null ? item.getNums() : 0;}).collect(Collectors.toList());
        eoutnums = regionResultVos.stream().map(item->{return item.getEoutnums() !=null ? item.getEoutnums() : 0;}).collect(Collectors.toList());
        etnums = regionResultVos.stream().map(item->{return item.getEtnums() !=null ? item.getEtnums() : 0;}).collect(Collectors.toList());

        innums.set(0,innums.stream().mapToLong(number-> number).sum());
        outnums.set(0,outnums.stream().mapToLong(number-> number).sum());
        deals.set(0,deals.stream().mapToLong(number-> number).sum());
        tnums.set(0,tnums.stream().mapToLong(number-> number).sum());
        rnums.set(0,rnums.stream().mapToLong(number-> number).sum());
        nums.set(0,nums.stream().mapToLong(number-> number).sum());
        eoutnums.set(0,eoutnums.stream().mapToLong(number-> number).sum());
        etnums.set(0,etnums.stream().mapToLong(number-> number).sum());

        regionResult.put("innums",innums);
        regionResult.put("outnums",outnums);
        regionResult.put("deals",deals);
        regionResult.put("tnums",tnums);
        regionResult.put("rnums",rnums);
        regionResult.put("nums",nums);
        regionResult.put("eoutnums",eoutnums);
        regionResult.put("etnums",etnums);
        return regionResult;
    }

}
